﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Microsoft.Ajax.Utilities;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using SignatureWebApi;
namespace SignatureWebApi.Models
{
    
    /// <summary>
    /// 航班手机数据请求模型
    /// </summary>
    public class FlightRequestMobileModels
    {
        /// <summary>
        /// 区域
        /// </summary>
        [Display(Name = "区域")]
        [EnumCheck(typeof(StandAreaEnum))]
        public StandAreaEnum? Area { get;set; }

        /// <summary>
        /// 机位
        /// </summary>
        [Display(Name = "机位")]
        public string Stand { get; set; }

        /// <summary>
        /// 航班号
        /// </summary>
        [Display(Name = "航班号")]
        public string FlightNumber { get; set; }
    }

    /// <summary>
    /// 航班任务请求模型
    /// </summary>
    public class FlightMissionRequestModels
    {
        /// <summary>
        /// 机位所属的区域
        /// </summary>
        [Display(Name = "区域")]
        [EnumCheck(typeof(StandAreaEnum))]
        public StandAreaEnum? Area { get; set; }

        /// <summary>
        /// 机位
        /// </summary>
        [BsonElement("stand")]
        public string Stand { get; set; }

        /// <summary>
        /// 到达时间
        /// </summary>
        [BsonElement("a_t")]
        public DateTime? ArrivalTime { get; set; }

        /// <summary>
        /// 出发时间
        /// </summary>
        [BsonElement("d_t")]
        public DateTime? DepartTime { get; set; }
    }

    /// <summary>
    /// 航班手机数据请求模型
    /// </summary>
    public  class FlightRequestWebModels
    {
        /// <summary>
        /// 区域
        /// </summary>
        [Display(Name = "区域")]
        [EnumCheck(typeof(StandAreaEnum))]
        public StandAreaEnum? Area { get; set; } 

        /// <summary>
        /// 机位
        /// </summary>
        [Display(Name = "机位")]
        public string Stand { get; set; }

        /// <summary>
        /// 航班号
        /// </summary>
        [Display(Name = "航班号")]
        public string FlightNumber { get; set; }

        /// <summary>
        /// 航空公司        
        /// </summary>
        [Display(Name = "航空公司")]
        public string Airline { get; set; }

        /// <summary>
        /// 任务状态        
        /// </summary>
        [Display(Name = "任务状态")]
        [EnumCheck(typeof(MissionStatus))]
        public MissionStatus? Status { get; set; }

        /// <summary>
        /// 执行执行日期
        /// </summary>
        [Display(Name = "执行日期")]
        [EnumCheck(typeof(MissionStatus))]
        public DateTime ExcuteTime { get; set; }
    }
    /// <summary>
    /// 手机航班信息返回模型
    /// </summary>
    [BsonIgnoreExtraElements]
    public class FlightReturnMobileModels
    {
        /// <summary>
        /// 唯一ID
        /// </summary>
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        [BsonElement("_id")]
        public string Id { get; set; }
        /// <summary>
        /// 机位
        /// </summary>
        [Display(Name = "机位")]
        [BsonElement("Stand")]
        public string Stand { get; set; }

        /// <summary>
        /// 航班号
        /// </summary>
        [Display(Name = "航班号")]
        [BsonElement("FlightNumber")]
        public string FlightNumber { get; set; }
        /// <summary>
        /// 任务
        /// </summary>
        [Display(Name = "任务")]
        [BsonElement("MissionType")]
        public MissionType MissionType { get; set; }
        /// <summary>
        /// 任务
        /// </summary>
        [Display(Name = "任务时间")]
        [BsonElement("MissionTime")]
        public DateTime? MissionTime { get; set; }
        /// <summary>
        /// 机型
        /// </summary>
        [Display(Name = "机型")]
        [BsonElement("PlaneType")]
        public string PlaneType { get; set; }
        /// <summary>
        /// 机号
        /// </summary>
        [Display(Name = "机号")]
        [BsonElement("PlaneNumber")]
        public string PlaneNumber { get; set; }
        /// <summary>
        /// 执行者
        /// </summary>
        [Display(Name = "执行者")]
        [BsonElement("Executor")]
        public string Executor { get; set; }
        /// <summary>
        /// 接单时间
        /// </summary>
        [Display(Name = "接单时间")]
        [BsonElement("OrderTakingTime")]
        public DateTime? OrderTakingTime { get; set; }
        /// <summary>
        /// 到位时间
        /// </summary>
        [Display(Name = "到位时间")]
        [BsonElement("ArrivalTime")]
        public DateTime? ArrivalTime { get; set; }
        /// <summary>
        /// 完成时间
        /// </summary>
        [Display(Name = "完成时间")]
        [BsonElement("CompleteTime")]
        public DateTime? CompleteTime { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        [Display(Name = "任务状态")]
        [BsonElement("Status")]
        public string Status { get; set; }

        ///// <summary>
        ///// 是否已关注
        ///// </summary>
        //[Display(Name = "关注")]
        //[BsonElement("Focus")]
        //public bool Focus { get; set; }
    }

    /// <summary>
    /// 网页航班信息返回模型
    /// </summary>
    [BsonIgnoreExtraElements]
    public class FlightReturnWebModels
    {
        /// <summary>
        /// 唯一ID
        /// </summary>
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        [BsonElement("_id")]
        public string Id { get; set; }
        /// <summary>
        /// 任务时间
        /// </summary>
        [Display(Name = "任务时间")]
        [BsonElement("MissionTime")]
        public DateTime? MissionTime { get; set; }
        /// <summary>
        /// 航班号
        /// </summary>
        [Display(Name = "航班号")]
        [BsonElement("FlightNumber")]
        public string FlightNumber { get; set; }
        /// <summary>
        /// 机号
        /// </summary>
        [Display(Name = "机号")]
        [BsonElement("PlaneNumber")]
        public string PlaneNumber { get; set; }

        /// <summary>
        /// 航空公司
        /// </summary>
        [Display(Name = "航空公司")]
        [BsonElement("Airline")]
        public string Airline { get; set; }
        /// <summary>
        /// 机型
        /// </summary>
        [Display(Name = "机型")]
        [BsonElement("PlaneType")]
        public string PlaneType { get; set; }
        /// <summary>
        /// 空调机体
        /// </summary>
        [Display(Name = "空调机体")]
        [BsonElement("PcaType")]
        public PcaType PcaType { get; set; }
        /// <summary>
        /// 机位
        /// </summary>
        [Display(Name = "机位")]
        [BsonElement("Stand")]
        public string Stand { get; set; }
        /// <summary>
        /// 预到时间
        /// </summary>
        [Display(Name = "预到时间")]
        [BsonElement("ETA")]
        public DateTime ETA { get; set; }
        /// <summary>
        /// 实到时间
        /// </summary>
        [Display(Name = "实到时间")]
        [BsonElement("ATA")]
        public DateTime ATA { get; set; }
        /// <summary>
        /// 预飞时间
        /// </summary>
        [Display(Name = "预飞时间")]
        [BsonElement("ETD")]
        public DateTime ETD { get; set; }
        /// <summary>
        /// 实飞时间
        /// </summary>
        [Display(Name = "实飞时间")]
        [BsonElement("ATD")]
        public DateTime ATD { get; set; }
        /// <summary>
        /// 任务类型
        /// </summary>
        [Display(Name = "任务类型")]
        [BsonElement("MissionType")]
        public MissionType MissionType { get; set; }
        /// <summary>
        /// 航班类型
        /// </summary>
        [Display(Name = "航班类型")]
        [BsonElement("FlightType")]
        public FlightType FlightType { get; set; }
        /// <summary>
        /// 执行者
        /// </summary>
        [Display(Name = "执行者")]
        [BsonElement("Executor")]
        public string Executor { get; set; }
        /// <summary>
        /// 任务生成时间
        /// </summary>
        [Display(Name = "生成时间")]
        [BsonElement("GenerateTime")]
        public DateTime GenerateTime { get; set; }
        /// <summary>
        /// 接单时间
        /// </summary>
        [Display(Name = "接单时间")]
        [BsonElement("OrderTakingTime")]
        public DateTime OrderTakingTime { get; set; }
        /// <summary>
        /// 到位时间
        /// </summary>
        [Display(Name = "到位时间")]
        [BsonElement("ArrivalTime")]
        public DateTime ArrivalTime { get; set; }
        /// <summary>
        /// 完成时间
        /// </summary>
        [Display(Name = "完成时间")]
        [BsonElement("CompleteTime")]
        public DateTime CompleteTime { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        [Display(Name = "任务状态")]
        [BsonElement("Status")]
        [BsonRepresentation(BsonType.String)]
        public int Status { get; set; }

        ///// <summary>
        ///// 是否已关注
        ///// </summary>
        //[Display(Name = "关注")]
        //[BsonElement("Focus")]
        //public bool Focus { get; set; }
    }


    /// <summary>
    /// 机位区域枚举
    /// </summary>
    public enum StandAreaEnum
    {
        /// <summary>
        /// 东一指廊
        /// </summary>
        East1,
        /// <summary>
        /// 东二指廊
        /// </summary>
        East2,
        /// <summary>
        /// 东三指廊
        /// </summary>
        East3,
        /// <summary>
        /// 东五指廊
        /// </summary>
        East5,
        /// <summary>
        /// 东六指廊
        /// </summary>
        East6,
        /// <summary>
        /// 东连接楼
        /// </summary>
        EastConnect,
        /// <summary>
        /// 西一指廊
        /// </summary>
        West1,
        /// <summary>
        /// 西二指廊
        /// </summary>
        West2,
        /// <summary>
        /// 西三指廊
        /// </summary>
        West3,
        /// <summary>
        /// 西五指廊
        /// </summary>
        West5,
        /// <summary>
        /// 西六指廊
        /// </summary>
        West6,
        /// <summary>
        /// 西连接楼
        /// </summary>
        WestConnect,
        /// <summary>
        /// 北指廊
        /// </summary>
        North,
        /// <summary>
        /// T1远机位
        /// </summary>
        RemotePositionT1,
        /// <summary>
        /// 东T2远机位
        /// </summary>
        EastRemotePositionT2,
        /// <summary>
        /// 西T2远机位
        /// </summary>
        WestRemotePositionT2

    }

    /// <summary>
    /// 机位对应的区域类
    /// </summary>
    public class StandArea
    {
        /// <summary>
        /// 东一机位
        /// </summary>
        public  string[] East1 { get; } = { "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112" };
        /// <summary>
        /// 东二机位
        /// </summary>
        public  string[] East2 { get; } = { "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123" };
        /// <summary>
        /// 东三机位
        /// </summary>
        public  string[] East3 { get; } = { "124", "125", "126", "127", "128", "129", "130", "131", "132", "133" };
        /// <summary>
        /// 东五机位
        /// </summary>
        public string[] East5 { get; } = { "144","145","146","147","148","149","150","151", "152", "153", "154" };
        /// <summary>
        /// 东连接楼机位
        /// </summary>
        public string[] EastConnect { get; } = { "152", "153", "154" };
        /// <summary>
        /// 东六机位
        /// </summary>
        public  string[] East6 { get; } = { "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170" };
        /// <summary>
        /// 北指廊机位
        /// </summary>
        public string[] North { get; } = { "168", "169", "170", "171", "172", "173" };
        /// <summary>
        /// 西一机位
        /// </summary>
        public string[] West1 { get; } = { "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213" };
        /// <summary>
        /// 西二机位
        /// </summary>
        public string[] West2 { get; } = { "214", "215", "216", "217", "218", "219", "220", "221", "222", "223" };
        /// <summary>
        /// 西三机位
        /// </summary>
        public string[] West3 { get; } = { "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235" };
        /// <summary>
        /// 西五机位
        /// </summary>
        public  string[] West5 { get; } = { "250", "251", "252", "253", "254", "255", "256", "257", "258", "259", "260", "261", "262", "263", "264" };
        /// <summary>
        /// 西连接楼机位
        /// </summary>
        public string[] WestConnect { get; } = { "261", "262", "263", "264" };
        /// <summary>
        /// 西六机位
        /// </summary>
        public string[] West6 { get; } = { "265", "266", "267", "268", "269", "270", "271", "272", "273", "274", "275", "276", "277", "278", "279", "171", "172", "173" };
        /// <summary>
        /// T1远机位
        /// </summary>
        public string[] RemotePositionT1 { get; } = { "" };
        /// <summary>
        /// T2东远机位
        /// </summary>
        public string[] EastRemotePositionT2 { get; } = { "309", "310", "311", "312", "313"};

        /// <summary>
        /// T2西远机位
        /// </summary>
        public string[] WestRemotePositionT2 { get; } = { "249","430", "431", "432", "433", "434", "435", "436", "437" };

    }
    
    /// <summary>
    /// 任务状态枚举
    /// </summary>
    public enum MissionStatus
    {
        /// <summary>
        /// 待接单
        /// </summary>
        待接,
        /// <summary>
        /// 已经接单
        /// </summary>
        已接,
        /// <summary>
        /// 已完成
        /// </summary>
        已完成,
        /// <summary>
        /// 紧急
        /// </summary>
        紧急
    }

    /// <summary>
    /// 任务类型枚举
    /// </summary>
    public enum MissionType
    {
        /// <summary>
        /// 靠廊桥
        /// </summary>
        靠廊桥,
        /// <summary>
        /// 撤廊桥
        /// </summary>
        撤廊桥,
        /// <summary>
        /// 靠桥载
        /// </summary>
        靠桥载,
        /// <summary>
        /// 撤桥载
        /// </summary>
        撤桥载
    }
    /// <summary>
    /// 航班类型
    /// </summary>
    public enum FlightType
    {
        /// <summary>
        /// 过站
        /// </summary>
        过站,
        /// <summary>
        /// 航前
        /// </summary>
        航前,
        /// <summary>
        /// 航后
        /// </summary>
        航后
    }
    /// <summary>
    /// 飞机空调类型类型
    /// </summary>
    public enum PcaType
    {
        /// <summary>
        /// 窄体机
        /// </summary>
        窄体机,
        /// <summary>
        /// 宽体机
        /// </summary>
        宽体机
    }
    /// <summary>
    /// 检查枚举值范围
    /// </summary>
    public class EnumCheckAttribute : ValidationAttribute
    {
        /// <summary>
        /// 初始化验证,判断输入的type是否为枚举类型
        /// </summary>
        /// <param name="enumType"></param>
        /// <exception cref="ArgumentException"></exception>
        public EnumCheckAttribute(Type enumType)
        {

            if (!enumType.IsEnum)
            {
                throw new ArgumentException("T must be an enumerated type");
            }
            Enum = enumType;
        }
        /// <summary>
        /// 错误提示
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            return "The value '" + this.ValueStr + "' is not valid for " + name + "parameter!";
        }

        /// <summary>
        /// 验证输入值是否在枚举中
        /// </summary>
        /// <param name="value">输入值</param>
        /// <returns></returns>
        public override bool IsValid(object value)
        {

            ValueStr = value?.ToString() ?? string.Empty;
            var isDefined = System.Enum.IsDefined(Enum, ValueStr);
            if (value == null)
            {
                return true;
            }
            if (!isDefined)
            {
                return false;
            }
            return true;

        }
        private string ValueStr { set; get; }
        /// <summary>
        /// 传入的Enum类型
        /// </summary>
        public Type Enum { set; get; }
    }

}